package com.ruoyi.business.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.business.domain.ShopBalance;
import com.ruoyi.business.service.IShopBalanceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商户余额Controller
 * 
 * @author wxy
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/balance")
public class ShopBalanceController extends BaseController
{
    @Autowired
    private IShopBalanceService shopBalanceService;

    /**
     * 查询商户余额列表
     */
    @RequiresPermissions("business:balance:list")
    @GetMapping("/list")
    public TableDataInfo list(ShopBalance shopBalance)
    {
        startPage();
        List<ShopBalance> list = shopBalanceService.selectShopBalanceList(shopBalance);
        return getDataTable(list);
    }

    /**
     * 导出商户余额列表
     */
    @RequiresPermissions("business:balance:export")
    @Log(title = "商户余额", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopBalance shopBalance)
    {
        List<ShopBalance> list = shopBalanceService.selectShopBalanceList(shopBalance);
        ExcelUtil<ShopBalance> util = new ExcelUtil<ShopBalance>(ShopBalance.class);
        util.exportExcel(response, list, "商户余额数据");
    }

    /**
     * 获取商户余额详细信息
     */
    @RequiresPermissions("business:balance:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopBalanceService.selectShopBalanceById(id));
    }

    @RequiresPermissions("business:balance:query")
    @GetMapping(value = "/shop/{mid}")
    public AjaxResult getShopInfo(@PathVariable("mid") Long mid)
    {
        return success(shopBalanceService.selectShopBalanceByShopId(mid));
    }

    /**
     * 新增商户余额
     */
    @RequiresPermissions("business:balance:add")
    @Log(title = "商户余额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopBalance shopBalance)
    {
        return toAjax(shopBalanceService.insertShopBalance(shopBalance));
    }

    /**
     * 修改商户余额
     */
    @RequiresPermissions("business:balance:edit")
    @Log(title = "商户余额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopBalance shopBalance)
    {
        return toAjax(shopBalanceService.updateShopBalance(shopBalance));
    }

    @RequiresPermissions("business:balance:edit")
    @Log(title = "商户余额", businessType = BusinessType.UPDATE)
    @PutMapping("/mid")
    public AjaxResult editByMid(@RequestBody ShopBalance shopBalance)
    {
        return toAjax(shopBalanceService.updateShopBalanceByMid(shopBalance));
    }

    /**
     * 删除商户余额
     */
    @RequiresPermissions("business:balance:remove")
    @Log(title = "商户余额", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shopBalanceService.deleteShopBalanceByIds(ids));
    }
}
